#ifndef STUFF_H

#define STUFF_H
#include <iostream>
#include<set>
#include <fstream>
#include<map>
#include<vector>
using namespace std;
class stuff
{
private:
    int ID;
    string name;
    int age;
    double wage;

    /* data */
public:
stuff(){}
    stuff(int inputID, string inputName, int inputAge, double inputWage);
    ~stuff();
    int getID() const { return ID; }
    string getName() const { return name; }
    int getAge() const { return age; }
    double getWage() const { return wage; }
    bool operator<(const stuff &c) const;
    friend istream &operator>>(istream &stm, stuff &A)
    {
        stm >> A.ID >> A.name >> A.age >> A.wage;
        return stm;
        
    }
    friend ostream &operator<<(ostream &stm, const stuff &A) 
    {
        //这里为了方便后面统一字符串处理，索性把写入都换成了字符串。
        stm  <<to_string(A.ID)  << " " << A.name << " " << to_string(A.age) << " " <<to_string( A.wage)<<'\n';
        return stm;
    }
};
// 这里是为了使用set写的比较函数
bool stuff ::operator<(const stuff &c) const
{
    return c.ID < ID;
}
stuff::stuff(int inputID, string inputName, int inputAge, double inputWage)
{
    ID = inputID;
    name = inputName;
    age = inputAge;
    wage = inputWage;
}

stuff::~stuff()
{
}
void task1_TB(){


//这里用set是贪图它自动排序的性质了hhhhhh
set <stuff> c;
// 测试样例
stuff s1(1850700,"ddv",12,12312);
stuff s2(1850701,"ddv1",12,12312);
stuff s3(1850702,"ddv2",12,12312);
stuff s4(1850703,"ddv3",12,12312);
stuff s5(1850704,"ddv4",12,12312);
c.insert(s1);
c.insert(s2);
c.insert(s3);
c.insert(s4);
c.insert(s5);

//输出部分，采用重载运算符的方式
ofstream outfile ;
outfile.open("../hw3.txt",ios::out|ios::trunc);
for (set<stuff>::iterator ite=c.begin();ite!=c.end();++ite)
{
    cout<<ite->getID()<<endl;
    outfile<<*(ite);
}
cout<<"第一次写入完成"<<endl;

// 输入输出测试，debug时候太麻烦了注释掉了
// stuff s6;
// cin>>s6;
// c.insert(s6);
// outfile<<s6;
// cin>>s6;
// c.insert(s6);
// outfile<<s6;
outfile.close();


// 读取文件，按行读取，并且将char*转为string，用vector后面输出方便，重新转换成class也会方便点。
ifstream infile("../hw3.txt",ios::in);
char cd[400];
vector<string> sum;
int ite=0;
while(infile.good())
{
infile.getline(cd,400);
string str(cd);
sum.push_back(str+'\n');
ite++;
// cout <<cd<<endl;
}
infile.close();
cout <<"读取结束,数据为："<<endl;
for(vector<string>::iterator ite=sum.begin();ite!=sum.end();++ite)
cout<<*ite;
//循环读取，采用string内部的find函数。
int flag=0;
for(vector<string>::iterator ite=sum.begin();ite!=sum.end();++ite)
{
    if(ite->find("1850700")!=-1)
    {
        cout<<"你要寻找的为："<<*ite;
        flag=1;
        break;
    }
 }
if(!flag)
{
    cout <<"没有找到相关匹配"<<endl;
}
}
#endif